package com.mjw.zstu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mjw.zstu.entity.Admin;
import com.mjw.zstu.mapper.AdminMapper;
import com.mjw.zstu.resultDto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminService {
    @Autowired
    AdminMapper adminMapper;
    public Admin login (Admin admin){
        return adminMapper.selectOne(new QueryWrapper<>(admin));
    }
    public JsonResult list(){
        QueryWrapper<Admin> q=new QueryWrapper<>();
        List l= adminMapper.selectList(q);
        return new JsonResult(200,"获取成功",l);
    }
    public JsonResult edit(Admin admin){
        adminMapper.updateById(admin);
        return new JsonResult(200,"编辑成功",null);
    }
    public JsonResult add(Admin admin){
        adminMapper.insert(admin);
        return new JsonResult(200,"新增成功",null);

    }
    public JsonResult delete(int id){
        adminMapper.deleteById(id);
        return new JsonResult(200,"删除成功",null);
    }
}
